﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DocViewer.Common;

public partial class Controls_ajax : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindData();
        }
    }

    private void BindData()
    {
        string op = SiteAbout.gStr("op");
        switch (op)
        {
            case "LeaveMsg":
                {
                    LeaveMsg();
                    break;
                }
            case "ListOwner":
                {
                    ListOwner();
                    break;
                }
            case "DeleteOwnerAndProc":
                {
                    DeleteOwnerAndProc();
                    break;
                }
            default:
                {
                    break;
                }
        }
    }

    private void DeleteOwnerAndProc()
    {
        string cardId=SiteAbout.gStr("cardId");
        int procId = SiteAbout.gInt("procId");
        DY.BLL.tbl_Protocol bllProc = new DY.BLL.tbl_Protocol();
        DY.BLL.tbl_Owner bllOwner = new DY.BLL.tbl_Owner();
        bllProc.Delete(procId);
        bllOwner.Delete(cardId);
    }

    private void LeaveMsg()
    {
        DY.BLL.tbl_Message bllMsg=new DY.BLL.tbl_Message();
        DY.Model.tbl_Message modelMsg = new DY.Model.tbl_Message();
        modelMsg.LoginName = CurUser.LoginName;
        modelMsg.TrueName = CurUser.Name;
        modelMsg.LeaveTime = DateTime.Now;
        modelMsg.Msg = SiteAbout.gStr("msg").Trim();
        if (!string.IsNullOrWhiteSpace(modelMsg.Msg))
            bllMsg.Add(modelMsg);
    }

    private void ListOwner()
    {
        //string curFolderId = SiteAbout.gStr("CurFolderId");
        //if (curFolderId == "")
        //{
        //    string res = "{\"aaData\":[],\"aoColumns\":[" +
        //        "{\"sTitle\":\"\",\"mData\":\"\",\"sClass\": \"center Name\"}," +
        //        "{\"sTitle\":\"协议编号\",\"mData\":\"ProtocolId\",\"sClass\": \"center Name\"}," +
        //        "{\"sTitle\":\"户主姓名\",\"mData\":\"Name\",\"sClass\": \"center\"}," +
        //        "{\"sTitle\":\"所属行政村\",\"mData\":\"VillageName\",\"sClass\": \"center\"}," +
        //        "{\"sTitle\":\"身份证号\",\"mData\":\"CardId\",\"sClass\": \"center\"}," +
        //        "{\"sTitle\":\"联系方式\",\"mData\":\"Mobile\",\"sClass\": \"center\"}," +
        //        "{\"sTitle\":\"安置人口\",\"mData\":\"Population\",\"sClass\": \"center\"}," +
        //        "{\"sTitle\":\"协议类型\",\"mData\":\"ProtocolType\",\"sClass\": \"center\"}," +
        //        "{\"sTitle\":\"\",\"mData\":\"文件名\",\"sClass\": \"center Name\"}" +
        //        "],\"path\":\"没有路径\",\"workPath\":\"\",\"headCount\":\"9\",\"newFolder\":\"0\",\"VisitCount\":\"\"}";
        //    Response.ContentType = "application/json";
        //    Response.Write(res);
        //    return;
        //}
        StringBuilder sb = new StringBuilder();
        //DY.BLL.tbl_Owner bllOwner = new DY.BLL.tbl_Owner();
        DY.BLL.View_UserWithProtocol bllView = new DY.BLL.View_UserWithProtocol();
        DataTable dt = bllView.GetAllList().Tables[0];
        foreach (DataRow dr in dt.Rows)
        {
            sb.Append("{");
            sb.Append("\"DT_RowId\":\"" + dr["CardId"].ToString() + "\",");
            sb.Append("\"operate\":\"<div class='hidden-phone visible-desktop action-buttons'>"+
                "<a class='blue' href=javascript:ViewInfo('" + dr["CardId"].ToString() + "',"+dr["id"].ToString()+")><i class='icon-zoom-in bigger-130'></i></a>" +
                "<a class='green' href=javascript:EditInfo('" + dr["CardId"].ToString() + "'," + dr["id"].ToString() + ")><i class='icon-pencil bigger-130'></i></a>" +
                "<a class='red' href=javascript:DeleteInfo('" + dr["CardId"].ToString() + "'," + dr["id"].ToString() + ")><i class='icon-trash bigger-130'></i></a></div>\",");
            sb.Append("\"ProtocolId\":\"" + dr["ProtocolId"].ToString() + "\",");
            sb.Append("\"Name\":\"" + dr["Name"].ToString() + "\",");
            sb.Append("\"VillageName\":\"" + dr["VillageName"].ToString() + "\",");
            sb.Append("\"CardId\":\"" + dr["CardId"].ToString() + "\",");
            sb.Append("\"Mobile\":\"" + dr["Mobile"].ToString() + "\",");
            sb.Append("\"Population\":\"" + dr["Population"].ToString() + "\",");
            sb.Append("\"ProtocolType\":\"" + dr["ProtocolType"].ToString() + "\"");
            sb.Append("},");
        }

        {
            string res = "{\"aaData\":["+sb.ToString().Trim(',')+"],\"aoColumns\":["+
                "{\"sTitle\":\"协议编号\",\"mData\":\"ProtocolId\",\"sClass\": \"center Name\"}," +
                "{\"sTitle\":\"户主姓名\",\"mData\":\"Name\",\"sClass\": \"center\"}," +
                "{\"sTitle\":\"所属行政村\",\"mData\":\"VillageName\",\"sClass\": \"center\"}," +
                "{\"sTitle\":\"身份证号\",\"mData\":\"CardId\",\"sClass\": \"center\"}," +
                "{\"sTitle\":\"联系方式\",\"mData\":\"Mobile\",\"sClass\": \"center\"}," +
                "{\"sTitle\":\"安置人口\",\"mData\":\"Population\",\"sClass\": \"center\"}," +
                "{\"sTitle\":\"协议类型\",\"mData\":\"ProtocolType\",\"sClass\": \"center\"}," +
                "{\"sTitle\":\"\",\"mData\":\"operate\",\"sClass\": \"center Name\"}" +
                "],\"path\":\"没有权限\",\"workPath\":\"\",\"headCount\":\"8\",\"newFolder\":\"0\",\"VisitCount\":\"\"}";
            Response.ContentType = "application/json";
            Response.Write(res);
        }
    }
}